package com.nine.mymall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author: duonine
 * @date: 2021/11/4
 */
@Configuration
public class MyRedissonConfig {

    /**
     * 所有对redis的操作都是通过RedissonClient去操作
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {
        Config config = new Config();
        // 单节点模式
        config.useSingleServer().setAddress("redis://192.168.56.10:6379");
        // 集群模式
        //config.useClusterServers().addNodeAddress("");
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }

}
